From: Adrian Vovk Date: Fri, 27 Feb 2026 21:21:46 +0000 (-0500) Subject: systemActions: Call into gnome-session for suspend X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~26^2~1^2~22 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=2e8eff96babbf47c76f208551d8ab55f89f9ad4b;p=gnome-shell.git systemActions: Call into gnome-session for suspend gnome-shell previously talked to logind directly on its own. This, however, will lead to code duplication: the various inhibitor handling bugfixes I've made to gnome-session (i.e. handling the new return values from CanPowerOff/CanReboot/CanSuspend) would have to be copied into gnome-shell. So instead, this commit just moves the responsibility for handling suspend into gnome-session. There's a corresponding change in gnome-session Part-of: --- diff --git a/data/dbus-interfaces/org.freedesktop.login1.Manager.xml b/data/dbus-interfaces/org.freedesktop.login1.Manager.xml index 7e0fc225e..acd49acb8 100644 --- a/data/dbus-interfaces/org.freedesktop.login1.Manager.xml +++ b/data/dbus-interfaces/org.freedesktop.login1.Manager.xml @@ -1,11 +1,5 @@ - - - - - - diff --git a/data/dbus-interfaces/org.gnome.SessionManager.xml b/data/dbus-interfaces/org.gnome.SessionManager.xml index 628a4693b..5c9ef11e3 100644 --- a/data/dbus-interfaces/org.gnome.SessionManager.xml +++ b/data/dbus-interfaces/org.gnome.SessionManager.xml @@ -5,12 +5,16 @@ + + + + diff --git a/js/misc/loginManager.js b/js/misc/loginManager.js index a66ebed03..da989b5b1 100644 --- a/js/misc/loginManager.js +++ b/js/misc/loginManager.js @@ -167,20 +167,6 @@ class LoginManagerSystemd extends Signals.EventEmitter { } } - async canSuspend() { - let canSuspend, needsAuth; - - try { - const [result] = await this._proxy.CanSuspendAsync(); - needsAuth = result === 'challenge'; - canSuspend = needsAuth || result === 'yes'; - } catch { - canSuspend = false; - needsAuth = false; - } - return {canSuspend, needsAuth}; - } - async canRebootToBootLoaderMenu() { let canRebootToBootLoaderMenu, needsAuth; @@ -213,10 +199,6 @@ class LoginManagerSystemd extends Signals.EventEmitter { return new SystemdLoginSession(Gio.DBus.system, 'org.freedesktop.login1', objectPath); } - suspend() { - this._proxy.SuspendAsync(true); - } - async inhibit(reason, cancellable) { const inVariant = new GLib.Variant('(ssss)', ['sleep', 'GNOME Shell', reason, 'delay']); @@ -268,13 +250,6 @@ class LoginManagerDummy extends Signals.EventEmitter { return new Promise(() => {}); } - canSuspend() { - return new Promise(resolve => resolve({ - canSuspend: false, - needsAuth: false, - })); - } - canRebootToBootLoaderMenu() { return new Promise(resolve => resolve({ canRebootToBootLoaderMenu: false, @@ -293,13 +268,6 @@ class LoginManagerDummy extends Signals.EventEmitter { return null; } - suspend() { - this._preparingForSleep = true; - this.emit('prepare-for-sleep', true); - this._preparingForSleep = false; - this.emit('prepare-for-sleep', false); - } - get preparingForSleep() { return this._preparingForSleep; } diff --git a/js/misc/systemActions.js b/js/misc/systemActions.js index 814746217..db559bfc2 100644 --- a/js/misc/systemActions.js +++ b/js/misc/systemActions.js @@ -86,6 +86,7 @@ const SystemActions = GObject.registerClass({ this._canHaveReboot = true; this._rebootNeedsAuth = false; this._canHaveSuspend = true; + this._suspendNeedsAuth = false; function tokenizeKeywords(keywords) { return keywords.split(';').map(keyword => GLib.str_tokenize_and_fold(keyword, null)).flat(2); @@ -162,7 +163,6 @@ const SystemActions = GObject.registerClass({ this._screenSaverSettings = new Gio.Settings({schema_id: SCREENSAVER_SCHEMA}); this._session = new GnomeSession.SessionManager(); - this._loginManager = LoginManager.getLoginManager(); this._monitorManager = global.backend.get_monitor_manager(); this._userManager = AccountsService.UserManager.get_default(); @@ -397,15 +397,19 @@ const SystemActions = GObject.registerClass({ } async _updateHaveSuspend() { - const {canSuspend, needsAuth} = await this._loginManager.canSuspend(); - this._canHaveSuspend = canSuspend; - this._suspendNeedsAuth = needsAuth; + try { + const [availability] = await this._session.CanSuspendAsync(); + this._canHaveSuspend = availability !== GnomeSession.ActionAvailability.UNAVAILABLE; + this._suspendNeedsAuth = availability === GnomeSession.ActionAvailability.CHALLENGE; + } catch { + this._canHaveSuspend = false; + this._suspendNeedsAuth = false; + } this._updateSuspend(); } _updateSuspend() { - const disabled = (Main.sessionMode.isLocked && - this._suspendNeedsAuth) || + const disabled = (Main.sessionMode.isLocked && this._suspendNeedsAuth) || (Main.sessionMode.isGreeter && this._loginScreenSettings.get_boolean(DISABLE_RESTART_KEY)); this._actions.get(SUSPEND_ACTION_ID).available = this._canHaveSuspend && !disabled; @@ -501,7 +505,7 @@ const SystemActions = GObject.registerClass({ if (!this._actions.get(SUSPEND_ACTION_ID).available) throw new Error('The suspend action is not available!'); - this._loginManager.suspend(); + this._session.SuspendAsync().catch(logErrorUnlessCancelled); } activateScreenshotUI() {